﻿using AutoMapper;
using MediatR;
using S.BreedingHistory.Api.Application.Commmand;
using S.BreedingHistory.Domain.Model;
using S.BreedingHistory.Infrastructure.Interface;

namespace S.BreedingHistory.Api.Application.CommmandHandler
{
    public class BreedingHistoryBatchAddCommandHandler : IRequestHandler<BreedingHistoryBatchAddCommand, bool>
    {
        private readonly IBreedingHistoryRepository breedingHistoryRepository;
        public BreedingHistoryBatchAddCommandHandler(IBreedingHistoryRepository breedingHistoryRepository)
        {
            this.breedingHistoryRepository = breedingHistoryRepository;
        }

        /// <summary>
        /// 种母历史记录的批量添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(BreedingHistoryBatchAddCommand request, CancellationToken cancellationToken)
        {
            //List<BreedingHistoryModel> breedingHistoryList = mapper.Map<List<BreedingHistoryModel>>(request.BreedingHistoryModelsList);
           foreach(var item in request.BreedingHistoryModelsList)
           {
                item.IsDel = true;
                item.IsEditor = true;
           }
            return await breedingHistoryRepository.BatchAddAsync(request.BreedingHistoryModelsList);
        }
    }
}
